const util = require("../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '',
    time: '',
    author: '',
    desc: '',
    description: '',
    likeNum: '',
    readNum: '',
    image: '',
    userImg: '',
    id: ''
  },

  onShareAppMessage: function () {
    return {
      title: title,
      path: `/pages/worksDetail/worksDetail?id=${id}`,
      imageUrl: '/lib/images/banner1.png'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    this.getWenZhagnDetail(options.id)
  },
  getWenZhagnDetail(id) {
    wx.showLoading({
      title: '拼命加载中',
    })
    wx.request({
      url: `https://jue.leheavengame.com/api/article/getArticleDetail?id=${id}`,
      success: (resquest) => {
        wx.hideLoading()
        const res = resquest.data.data
        this.setData({
          title: res.title.trim(),
          time: res.article.meta.createdAt.substr(0, 10),
          author: res.user && res.user.nickname,
          desc: res.article.description,
          readNum: res.article.readNum,
          likeNum: res.article.likeNum,
          description: res.article.content,
          image: res.article.screenshot || 'https://www.qqlykm.cn/api/ACG/api.php',
          userImg: res.user && res.user.headImg
        })
      },
      fail: (err) => {
        wx.hideLoading()
      }
    })
  }
})